<template>
  <div class="side">

    <div class="egister">
      <el-row>
        <el-button type="primary" @click="createData" class="dakai">提交</el-button>
      </el-row>
    </div>
    <div style="width:100%">
      <el-form style="margin-top:10px;" :model="ClassRoomSet" label-position="right" label-width="196px" ref="dataForm">

        <el-form-item label="班级称谓设置">
          <el-input v-model="ClassRoomSet.name" style="width:310px;"/>
          <p style="margin:0;color:#606266">用户所能看到的是这里设置的称谓</p>
          <div class="foot">
            <div>请注意：以下设置涉及到班级的基本运作模式，请谨慎设置，且不要经常性变更！</div>
          </div>
        </el-form-item>

        <el-form-item label="课程重合时抵扣购买 ">
          <el-radio-group v-model="ClassRoomSet.isBuy">
            <el-radio label="1">是</el-radio>
            <el-radio label="0">否</el-radio>
          </el-radio-group>
          <p style="margin:0;;color:#606266;">购买班级时，如果已经购买过其中的课程，支付金额中将会扣除该课程的当前价格。反之，支付金额不受影响，以班级原价购买。 </p>
        </el-form-item>

        <el-form-item label="班级列表页默认排序 ">
          <el-radio-group v-model="ClassRoomSet.defaultSort">
            <el-radio label="1">最新</el-radio>
            <el-radio label="2">最热</el-radio>
            <el-radio label="3">推荐</el-radio>
          </el-radio-group>
          <p style="width:546px;height:66px;line-height:22px;margin:0;color:#606266;"><a style="color:#428bcb">班级列表</a>页地址：域名/classroom/explore,任何人都可在此页面查看网站所有已发布班级,如需设置网站首页班级排序，请到【站点设置】-【主题】-【管理】中设置，目前仅简墨和雅致简洁主题支持。 </p>
        </el-form-item>

        <el-form-item label="班级中允许显示班级人数 ">
          <el-radio-group v-model="ClassRoomSet.isShow">
            <el-radio label="1">开启</el-radio>
            <el-radio label="0">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>

  import {addClassRoomSet, getClassRoomSet} from '@/api/system/class_room_set';
  import {getTenantId} from '@/utils/auth';

  export default {
    data() {
      return {
        ClassRoomSet: {
          name: '',
          isBuy: '',
          defaultSort: '',
          isShow: ''
        }
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        getClassRoomSet(getTenantId()).then(response => {
          this.ClassRoomSet = response.data
        }).catch(err => {
          console.log(err)
        })
      },
      createData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.ClassRoomSet.tenantId = getTenantId();
            addClassRoomSet(this.ClassRoomSet).then(() => {
              this.$notify({
                title: '成功',
                message: '创建成功',
                type: 'success',
                duration: 2000
              });
              this.fetchData();
            })
          }
        })
      }
    }
  }
</script>

<style scoped>
  .dakai {
    float: right;
    position: absolute;
    right: 10px;
    bottom: -25px;
  }

  .egister {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #e7e9ed;
    padding-top: 15px;
    padding-right: 34px;
  }

  .foot {
    width: 630px;
    margin-top: 20px;
    padding: 15px 15px;
    border-radius: 5px;
    background-color: #d9edf7;
    color: #326f8f;
    border-left: 5px solid #50bfff;
  }
</style>
